<template>
	<RouterView v-slot="{ Component }">
		<KeepAlive>
			<Component :is="Component" />
		</KeepAlive>
	</RouterView>
	<PageLoad :show="pageLoadStore.show" />
</template>

<script lang="ts" setup>
import { usePageLoad } from "@/stores/usePageLoad";
import PageLoad from "@/components/PageLoad.vue";
import { userInit } from "@/services/init/user-init";

const pageLoadStore = usePageLoad();
init();
function init() {
	userInit({ token: getToken() }).catch(() => {
		throw new Error("Not logined");
	});
}
function getToken() {
	let index = location.href.indexOf("?token=") || location.href.indexOf("&token=");
	let str = index == -1 ? "" : location.href.slice(index + 7);
	let endIndex = str.indexOf("&");
	return str.slice(0, endIndex == -1 ? str.length : endIndex);
}
</script>
